package cn.bocai.pc.web.portal;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.bocai.pc.model.BcCollect;
import cn.bocai.pc.model.BcDrawing;
import cn.bocai.pc.model.BcLinktble;
import cn.bocai.pc.model.BcLinktype;
import cn.bocai.pc.model.BcPicture;
import cn.bocai.pc.model.BcUser;
import cn.bocai.pc.service.BcCollectService;
import cn.bocai.pc.service.BcDrawingService;
import cn.bocai.pc.service.BcLinktypeService;
import cn.bocai.pc.service.BcPictureService;
import cn.bocai.pc.service.BcThumpicService;
import cn.bocai.pc.service.BcLinktbleService;
import cn.bocai.pc.service.VariableService;
import cn.bocai.pc.util.UUIDUtils;

@Controller
@RequestMapping("/skip")
public class SkipPageController {
	@Autowired
	private BcThumpicService bcThumpicService;
	@Autowired
	private BcLinktbleService bcLinktbleService;
	@Autowired
	private BcLinktypeService bcLinktypeService;
	@Autowired
	private BcCollectService bcCollectService;
	@Autowired
	private BcPictureService bcPictureService;
	@Autowired
	private VariableService variableService;
	@Autowired
	private BcDrawingService bcDrawingService;
	
	@RequestMapping("/afterLogin/homePaging.do")
	public String delectThumOne() {
		return "bcPage/prompt/publicPrompt";
	}

	/**
	 * 进入首页将
	 * @time 2015/07/04
	 */
	@RequestMapping("/index.do")
	public String index(HttpServletRequest request, HttpServletResponse response,Model m) {
		String variable=variableService.selectVariable("PIC_URL");
		String variableYear=variableService.selectVariable("year");
		String varHtmlUrl = variableService.selectVariable("HTML_URL");//http://localhost:8080/pc-portal	
		String porUrl=variableService.selectVariable("POR_URL");//静态页面磁盘映射
		
			 Map<String, Object> playMap = new HashMap<String,Object>();
			 playMap.put("year",variableYear);
			//查询首页轮播图的地址
			List<Map<String, Object>> playArrayList = bcThumpicService.getSelectRecommend(playMap);
		
		m.addAttribute("url",variable);
		m.addAttribute("year",variableYear);
		m.addAttribute("bcUrl",varHtmlUrl);
		m.addAttribute("moveList",playArrayList);
		m.addAttribute("porUrl",porUrl);
		
		
		
		//查询友情链接类型参数1表示类型
		List<BcLinktype> selectByFriendship = bcLinktypeService.selectByFriendship("1");
		List<Map<String, Object>> arrayList = new ArrayList<Map<String, Object>>();
		 for(BcLinktype tmp:selectByFriendship){
			 Map<String,Object> map=new HashMap<String,Object>();
			//通过类型id查询出对应的链接信息
			 List<BcLinktble> selectByLink = bcLinktbleService.selectByLink(tmp.getId());
			 map.put("LinkKey",tmp.getLinkTypename());
			 map.put("LinkVal",selectByLink);
			 arrayList.add(map);
	        }
		 m.addAttribute("arrayList",arrayList);
		return "bcPage/index";

		// return "bcPage/publicHead";
	}

	// 跳入彩色图库
	@RequestMapping("/coloursPage.do")
	public String coloursbcPage(HttpServletRequest request, HttpServletResponse response,Model m) {
		mainColBlack(request,m,"1");
		return "bcPage/coloursPage";
	}

	// 跳入黑白图库
	@RequestMapping("/blackPage.do")
	public String blackbcPage(HttpServletRequest request, HttpServletResponse response,Model m) {
		mainColBlack(request,m,"0");
		return "bcPage/blackPage";
	}
	//彩色和黑白的页面进入扫描
		public void mainColBlack(HttpServletRequest request,Model m,String colour){
			//到数据字典去查询出对的的值
			String variable=variableService.selectVariable("PIC_URL");//http://localhost:8081/pc-image
			String variableYear=variableService.selectVariable("year");
			String varHtmlUrl = variableService.selectVariable("HTML_URL");//http://localhost:8080/pc-portal
			String porUrl = variableService.selectVariable("POR_URL");//磁盘映射静态页面
			int searRowAll = bcThumpicService.searRowAll(colour);//获取最后一条数据的对象值
			String colous="";
			String returnUrl="";
			if("1".equals(colour)){
				colous="col";
				returnUrl="coloursPage.do";
			}else{
				colous="black";
				returnUrl="blackPage.do";
			}
			m.addAttribute("porUrl",porUrl);
			m.addAttribute("url",variable);
			m.addAttribute("year",variableYear);
			m.addAttribute("colous",colous);
			m.addAttribute("bcUrl",varHtmlUrl);
			m.addAttribute("nowUrl",varHtmlUrl+"/skip/"+returnUrl);
			m.addAttribute("endRow",searRowAll);//总行数
		    Map<String, String> articleMap = new HashMap<String,String>();
				articleMap.put("year", variableYear);
				articleMap.put("colour",colour);
					
		  List<Map<String, Object>> returnColOrBlack = bcPictureService.selectColOrBlack(articleMap);
			
			m.addAttribute("selectColOrBlack",returnColOrBlack);
		}
	
	/**
	 * 点击页面右上角查看具体年份的图片
	 * @param year  年份
	 * @param colour  颜色
	 * @time 2015/07/13
	 */
	@RequestMapping("/{year}/{colour}.do")
	public String scanPic(@PathVariable String year,@PathVariable String colour,HttpServletRequest request,Model m){
		String returnpage="col".equals(colour)?"bcPage/coloursPage":"bcPage/blackPage";
		String colous="col".equals(colour)?"1":"0";
		
		//到数据字典查询出要的数据值
		String variable=variableService.selectVariable("PIC_URL");//http://localhost:8081/pc-image
		String varHtmlUrl = variableService.selectVariable("HTML_URL");//http://localhost:8080/pc-portal
		String porUrl = variableService.selectVariable("POR_URL");//磁盘映射静态页面
		m.addAttribute("porUrl",porUrl);
		m.addAttribute("url",variable);
		m.addAttribute("year",year);
		m.addAttribute("colous",colour);
		m.addAttribute("bcUrl",varHtmlUrl);
		m.addAttribute("nowUrl",varHtmlUrl+"/skip/"+year+"/"+colour+".do");
		//传入要的条件进行查询
		Map<String, String> beforeCMap = new HashMap<String,String>();
		beforeCMap.put("year", year);
		beforeCMap.put("colour",colous);
        List<Map<String, Object>> returnColOrBlack = bcPictureService.selectColOrBlack(beforeCMap);
		m.addAttribute("selectColOrBlack",returnColOrBlack);
		
		return returnpage;
	}
	
	

	// 跳入注册账号
	@RequestMapping("/register.do")
	public String register() {

		return "bcPage/accounts/register";
	}

	// 跳入登入账号
	@RequestMapping("/login.do")
	public String login() {
		return "bcPage/accounts/login";
	}

	// 跳入修改密码账号
	@RequestMapping("/forgetPwd.do")
	public String forgetPwd() {
		return "bcPage/accounts/forgetPwd";
	}
	
	/** afterLogin 是表示登入以后才能看到的页面，这些页面都做了拦截处理 */
	// 登入成功进如收藏页面的3个页面
	@RequestMapping("/afterLogin/afLoCollect.do")
	public String publicAfterLogin(HttpServletRequest request,Model m) {
		String variableUrl=variableService.selectVariable("PIC_URL");//http://localhost:8081/pc-image
		String varHtmlUrl = variableService.selectVariable("HTML_URL");//http://localhost:8080/pc-portal
		String porUrl = variableService.selectVariable("POR_URL");//磁盘映射静态页面
		
		m.addAttribute("url",variableUrl);
		m.addAttribute("bcUrl",varHtmlUrl);
		m.addAttribute("porUrl",porUrl);
		String variable=null;
		String parameter = request.getParameter("type");
		if(null==parameter){
			variable=CommPaging(request,m,variable);
		}else if("1".equals(parameter)){
			variable="bcPage/afterLogin/afLoCollectTwo";
			pubSelectCollect(request,m,"1");
		}else if("2".equals(parameter)){
			variable="bcPage/afterLogin/afLoCollectTree";
			pubSelectCollect(request,m,"0");
		}
		
		return variable;
	}
	//收藏页面的公共方法
	public void pubSelectCollect(HttpServletRequest request,Model m,String tempColour){
		 BcUser attribute =(BcUser)request.getSession().getAttribute("selectLogin");
		 String colous="1".equals(tempColour)?"col":"black";
		 
		//到数据字典去查询出对的的值
		 String variable=variableService.selectVariable("PIC_URL");
		//到数据字典查询出要的数据值
		 String variableYear=variableService.selectVariable("year");
		 HashMap<String, Object> map = new HashMap<String, Object>();
			 map.put("id",attribute.getUserId());
			 map.put("colour",tempColour);
			 map.put("year",variableYear);
		 
		 //根据传入的条件查询出收藏者收藏的图片
		 List<Map<String, Object>> topColocoList = bcThumpicService.selectColCollect(map);
		 m.addAttribute("topColList",topColocoList);
		 
		 List<Map<String, Object>> selectColOrBlack = bcThumpicService.selectThumColCollect(map);
		 m.addAttribute("colList",selectColOrBlack);//查询出略缩图信息
		 
		 m.addAttribute("url",variable);//图片显示的服务器地址
	     m.addAttribute("colous",colous);
	     m.addAttribute("year",variableYear);//最新的
	}
	
	
	//查看收藏页面的浏览期数
	@RequestMapping("/afterLogin/browsePer.do")
	public String browsePer(HttpServletRequest request,Model m) {
		String variable=variableService.selectVariable("PIC_URL");//http://localhost:8081/pc-image
		String parThumPicId = request.getParameter("thumPicId");
		String parYears = request.getParameter("years");
		//设置参数
		Map<String, String> map=new HashMap<String, String>();
			map.put("thumPicId", parThumPicId);
			map.put("year", parYears);
		List<BcPicture> selectAllPeriods = bcPictureService.selectAllPeriods(map);//获取所有指定参数的数据
		 m.addAttribute("BcPicture",selectAllPeriods);//放入模型中
		 m.addAttribute("url",variable);//放入模型中
		return "bcPage/afterLogin/browse/browsePer";
	}
	
	// 跳转进如修改密码
	@RequestMapping("/afterLogin/alterPassword.do")
	public String alterPassword() {
		return "bcPage/afterLogin/alterPassword";
	}

	
	/**
	 * 收藏页面的ajax请求，保存收藏的数据
	 * @throws ParseException 
	 * @time 2015/07/07
	 */
	@RequestMapping("/afterLogin/installThumId.do")
	public void installThumId(HttpServletRequest request, HttpServletResponse response,BcCollect record,Model m){
		BcUser attribute = (BcUser)request.getSession().getAttribute("selectLogin");
		String judges = request.getParameter("judge");
		String parameter = request.getParameter("uuid");
		String year = request.getParameter("year");
		String colour = request.getParameter("colour");
		int insert = 2;
		String uuid ="";
	//judges传过来的值是add就是添加，如果传过来的是del就删除	
     if("add".equals(judges)){
    	 Date date=new Date(); 
    	 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    	 String format = dateFormat.format(date);
    	/* Date parse = dateFormat.parse(format);*/
    	uuid = UUIDUtils.getUUID32();
    	record.setId(uuid);
 		record.setBcUserId(attribute.getUserId());
 		record.setColTime(format);
 		record.setColPictype("1");//标示前段判断使用的
 		record.setRemarks1(parameter);
 		record.setColYear(year);
 		record.setColour(colour);
 		insert = bcCollectService.insert(record);
 		
     }else if("del".equals(judges))	{
    	 HashMap<String, String> map = new HashMap<String, String>();
		 map.put("bcUserId", attribute.getUserId());
		 map.put("id", parameter);
		int delinsert = bcCollectService.deleteBcCollect(map);
     }
     
     PrintWriter out=null;
		 try {
			 out = response.getWriter();
			 if(insert==1){
			 out.print("1_"+uuid);
			 }else if(insert==0){ 
			 out.print("2_"+"");	
		    }else{
		      out.print("0_"+"");
		    }
		} catch (IOException e) {
			e.printStackTrace();
		} 
	}
	
	
	
	/**
	 * 收藏页面首页的图片删除
	 * @throws ParseException 
	 * @time 2015/07/07
	 */
	@RequestMapping("/afterLogin/delectThumOne.do")
	public String delectThumOne(HttpServletRequest request,Model m) {
		BcUser attribute = (BcUser)request.getSession().getAttribute("selectLogin");
		String thumId = request.getParameter("uuid");
		
		 HashMap<String, String> map = new HashMap<String, String>();
		 map.put("bcUserId", attribute.getUserId());
		 map.put("id", thumId);
		int delinsert = bcCollectService.deleteBcCollect(map);
		
		if(1==delinsert){
			m.addAttribute("msg", "删除成功");
		}else{
			m.addAttribute("msg", "删除失败");
		}
		m.addAttribute("skipUrl", "/skip/afterLogin/afLoCollect.do");
		return "bcPage/prompt/publicPrompt";
	}
	
	
	/**
	 * 页面搜索功能
	 * @throws ParseException 
	 * @time 2015/07/08
	 */
	@RequestMapping("/searchStructure.do")
	public String searchStructure(HttpServletRequest request,Model m) {
		String parType = request.getParameter("type"); //获取查找类型是全部还是彩色还是黑白等
		String returnAddress="bcPage/searchFile/searchStructure";
		String variableUrl=variableService.selectVariable("PIC_URL");//http://localhost:8081/static
		String porUrl = variableService.selectVariable("POR_URL");//磁盘映射静态页面
		
		String baUrl = variableService.selectVariable("BA_URL");//http://localhost:8081
		String drawUrl = variableService.selectVariable("DRA_UEL");///drawPic
		
		//当类型为3的是时候表示未全年图纸
		if(parType.equals("3")){
			variableUrl=baUrl+drawUrl;
			porUrl=drawUrl;
		}
		m.addAttribute("url",variableUrl); //获取项目名称
		m.addAttribute("porUrl",porUrl); 
		String method = request.getMethod();//回去请求的类型
		String parKeyword="";
		if("POST".equalsIgnoreCase(method)){
			   parKeyword = request.getParameter("keyword"); //获取要查找的内容
		}else{
			 try {
		       parKeyword=new String (request.getParameter("keyword").getBytes("ISO-8859-1"),"utf-8");//中文get形式传输需要转码
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		m.addAttribute("showMessage",parKeyword);
		m.addAttribute("colourType",parType);
		m.addAttribute("type",parType);
		if(!("快速找图？？请输入搜索关键字").equals(parKeyword) && !"".equals(parKeyword)){
		     searchPaging(request,m,parType,parKeyword); //根据内容查询出内容出需要的数据
		}else if("".equals(parKeyword)){
	    //当查询的内容为空的时候就要提示跳转
		  //调取页面隐藏的访问路径，这边好跳转回去
		  String requestURI = request.getParameter("returnUrl");
		  int startIndexOf = requestURI.lastIndexOf("/");
		  int endIndexOf = requestURI.lastIndexOf(".");
		  String substring = requestURI.substring(startIndexOf+1,endIndexOf);
		  m.addAttribute("msg", "请输入要搜索的关键字");
		  //如果在搜索的结果页面输入为空的时候就要跳转到首页，因为搜索结果页面是需要参数才能显示 的
		  if("searchStructure".equals(substring)||"".equals(substring)){
			  m.addAttribute("skipUrl","/skip/index.do");
			  returnAddress="bcPage/prompt/publicPrompt";//跳转到提示页面
		  }else{
			  m.addAttribute("skipUrl",requestURI);
			  returnAddress="bcPage/prompt/publicPromptOther";//跳转到提示页面
		  }
		}
		return returnAddress;
	}
	
	/**
	 * 收藏页面首页的分页显示
	 * @time 2015/07/07
	 */
	public String CommPaging(HttpServletRequest request,Model m,String variable){
		BcUser attribute =(BcUser)request.getSession().getAttribute("selectLogin");
		variable="bcPage/afterLogin/afLoCollect";
		        
		      String _ps = request.getParameter("pageSize");
		        //1:定义每页显示多少行记录
				int pageSize = 12;
				 //将获取到前台的用户要求的显示的第几页数据转化为整型类型数据
				if(_ps!=null && !_ps.trim().equals("")){
					try{
						pageSize = Integer.parseInt(_ps);
					}catch(Exception e){
						//不处理
					}
				}
				
				//2:获取用户要求显示第几页
				String _cp = request.getParameter("currentPageNumber");
				//默认等于第一页
				int currentPage = 1;
		         //将获取到前台的用户要求的显示的第几页数据转化为整型类型数据
				if(_cp!=null && !_cp.trim().equals("")){
					try{
						currentPage = Integer.parseInt(_cp);
					}catch(Exception e){
						//不处理
					}
				}
				try{
					//执行查询出全部数据的总行数
					int rowCount = bcCollectService.selectAllRow(attribute.getUserId());
					//4:计算一共分多少页
					int pageCount = rowCount/pageSize+(rowCount%pageSize==0?0:1);
					//判断当前页面要求页数是否已经大于pageCount（总页数）最大页数，如果大于就拿总页数否则就拿页面要求的
					currentPage=(currentPage>pageCount?pageCount:currentPage);
					//判断
			     	currentPage=(currentPage<=0?1:currentPage);
					//5:计算从哪一行开始查询
					int start = (currentPage-1)*pageSize;
					
					//6:查询出指定行数的数据
					 Map<String, Object> map = new HashMap<String, Object>();
					 map.put("id",attribute.getUserId());
					 map.put("start",start);
					 map.put("pageSize",pageSize);
					 /*List<BcThumpic> datas = bcThumpicService.selectAllThum(map);*/
					 List<BcCollect> datas = bcCollectService.seleCollectAll(map);
					 
					 //创建收集使用的list
					 List<Map<String, Object>> collectList = new ArrayList<Map<String, Object>>();
						for(int b=0;b<datas.size();b++){
							//创建传参使用的map
							 Map<String, String> collectMap = new HashMap<String,String>();
							 collectMap.put("id", datas.get(b).getId());
							 collectMap.put("thumpicId",datas.get(b).getRemarks1());
							 collectMap.put("year",datas.get(b).getColYear());
							 collectMap.put("periods",datas.get(b).getColPeriods());
							//查询出每条对应数据
							Map<String, Object> moveList = bcThumpicService.getSelectCollect(collectMap);
			                 collectList.add(moveList);//将对应的每一个map值放到list中去
						}
					//封装数据将传到前台数据
					 m.addAttribute("datas", collectList);//查询出的数据
					 m.addAttribute("pageCount",pageCount);//一个分多少页
					 m.addAttribute("currentPage", currentPage);//当前页数
					 m.addAttribute("rowCount", rowCount);//一共多少条数据
					 m.addAttribute("pageSize", pageSize);//每页显示的条数
					 
					//以下计算开始显示的页码和结束显示的页码
						int showCount = 10;  //页面显示多少个页码
						int showStart = 0;   //
						int showEnd = 0;     //
						//如果总页码还不够15页
						if(pageCount<=showCount){
							showStart=1;
							showEnd=pageCount;//那么结束页面就等于总页码
						}else{//分页显示页码
							if(currentPage<=(showCount/2)){
								showStart=1;
								showEnd=showCount;
							}else{
								showStart=currentPage-(showCount/2-1);
								showEnd=showStart+(showCount-1);
							}
							//如果showEnd已经超出总页面
							if(showEnd>=pageCount){ //最后的页面大于等于总页码
								showEnd=pageCount;
								showStart=showEnd-(showCount-1);
							}
						}
						m.addAttribute("showStart",showStart);
						m.addAttribute("showEnd",showEnd);

				}catch(Exception e){
					throw new RuntimeException(e);
				}
		return variable;
	}

	
	
	/**
	 * 搜索分页
	 * @time 2015/07/07
	 */
	public void searchPaging(HttpServletRequest request,Model m,String parType,String parKeyword){
		/*String year = bcDrawingService.pulDownYearOne();// 所有年份中最新的年份
*/		String year = variableService.selectVariable("year");//获取当年的年份
		      String _ps = request.getParameter("pageSize");
		        //1:定义每页显示多少行记录
				int pageSize = 12;
				 //将获取到前台的用户要求的显示的第几页数据转化为整型类型数据
				if(_ps!=null && !_ps.trim().equals("")){
					try{
						pageSize = Integer.parseInt(_ps);
					}catch(Exception e){
						//不处理
					}
				}
				
				//2:获取用户要求显示第几页
				String _cp = request.getParameter("currentPageNumber");
				//默认等于第一页
				int currentPage = 1;
		         //将获取到前台的用户要求的显示的第几页数据转化为整型类型数据
				if(_cp!=null && !_cp.trim().equals("")){
					try{
						currentPage = Integer.parseInt(_cp);
					}catch(Exception e){
						//不处理
					}
				}
				try{
					Map<String,Object> searMap = new HashMap<String,Object>();
				     searMap.put("parType", parType);
				     searMap.put("parKeyword", parKeyword);
					int rowCount = bcThumpicService.searAllRow(searMap);
					//当类型为3的时候表示全年图纸查询
					if(parType.equals("3")){
						Map<String, Object> searCount = new HashMap<String, Object>();
						searCount.put("parKeyword", parKeyword);// 传递过来的参数
						searCount.put("year", year);// 传递过来的年份
						rowCount = bcDrawingService.searAllRowAll(searCount);// 查询搜索的时候的值总行数
					}
					/*selectAllRow=(null==selectAllRow?"0":selectAllRow);
					//执行查询出全部数据的总行数
					int rowCount = Integer.parseInt(selectAllRow);*/
					//4:计算一共分多少页
					int pageCount = rowCount/pageSize+(rowCount%pageSize==0?0:1);
					//判断当前页面要求页数是否已经大于pageCount（总页数）最大页数，如果大于就拿总页数否则就拿页面要求的
					currentPage=(currentPage>pageCount?pageCount:currentPage);
					//判断
			     	currentPage=(currentPage<=0?1:currentPage);
					//5:计算从哪一行开始查询
					int start = (currentPage-1)*pageSize;
					String variableYear=variableService.selectVariable("year");
					//6:查询出指定行数的数据
				     searMap.put("start",start);
				     searMap.put("pageSize",pageSize);
				     searMap.put("year",variableYear);
				     String oriName="";//原始的名称
				     List<Map<String, Object>> searchList = bcThumpicService.getSelectsearch(searMap);
				     //当类型为3的时候表示全年图纸查询
				     if(parType.equals("3")){
					     Map<String, Object> searMap1 = new HashMap<String, Object>();
							searMap1.put("start", start);
							searMap1.put("pageSize", pageSize);
							searMap1.put("year", year);
	                        searMap1.put("parKeyword", parKeyword);
								 searchList = bcDrawingService.bcSearDataPic(searMap1);
				     }
				     for (int i=0;i<searchList.size();i++){
					        Map<String, Object> map = searchList.get(i);
					        String para= (String) map.get("PicName");
					        oriName=para;
					        String Desc= (String) map.get("Desctibe");
					        int paralenStr = para.length();
					        int DesclenStr = Desc.length();
					        String replaceAll1= para.replaceAll(parKeyword,"<font color=\"red\">"+parKeyword+"</font>");
					        String replaceAll2= Desc.replace(parKeyword,"<font color=\"red\">"+parKeyword+"</font>");
					        int paralenEnt = replaceAll1.length();
					        int DesclenEnt = replaceAll2.length();
					        if(paralenStr!=paralenEnt){
					        	map.put("PicName", replaceAll1);
					        }
					        if(DesclenStr!=DesclenEnt){
					        	map.put("Desctibe", replaceAll2);
					        }
					 }
				     
				     String varHtmlUrl = variableService.selectVariable("HTML_URL");///pc-portal
					//封装数据将传到前台数据
					 m.addAttribute("datas",searchList);//查询出的数据
					 m.addAttribute("pageCount",pageCount);//一个分多少页
					 m.addAttribute("currentPage", currentPage);//当前页数
					 m.addAttribute("rowCount", rowCount);//一共多少条数据
					 m.addAttribute("pageSize", pageSize);//每页显示的条数
					 m.addAttribute("year", variableYear);//年份
					 m.addAttribute("bcUrl",varHtmlUrl);//对象名称
					 m.addAttribute("oriName",oriName);//替换之前的名称
					//以下计算开始显示的页码和结束显示的页码
						int showCount = 10;  //页面显示多少个页码
						int showStart = 0;   //
						int showEnd = 0;     //
						//如果总页码还不够15页
						if(pageCount<=showCount){
							showStart=1;
							showEnd=pageCount;//那么结束页面就等于总页码
						}else{//分页显示页码
							if(currentPage<=(showCount/2)){
								showStart=1;
								showEnd=showCount;
							}else{
								showStart=currentPage-(showCount/2-1);
								showEnd=showStart+(showCount-1);
							}
							//如果showEnd已经超出总页面
							if(showEnd>=pageCount){ //最后的页面大于等于总页码
								showEnd=pageCount;
								showStart=showEnd-(showCount-1);
							}
						}
						m.addAttribute("showStart",showStart);
						m.addAttribute("showEnd",showEnd);
				}catch(Exception e){
					throw new RuntimeException(e);
				}
	}
	
	//测试使用的
		@RequestMapping("TestHead.do")
	public String TestHead(HttpServletRequest request, HttpServletResponse response){
			return "bcPage/headOfpublic/TestHead";
	}
		
		
		
		
		
	//监测用户有没有登入
		@RequestMapping("checkoutLogin.do")
	public void checkoutLogin(HttpServletRequest request, HttpServletResponse response,PrintWriter out){
		BcUser user=(BcUser)request.getSession().getAttribute("selectLogin"); 
		String result ="";
		if(null!=user){
		  result =user.getUsername();
		}
		/*String result = "{\"relativePath\":\"/thumb/"+colourType+"/"+oriFName+"\", \"path\":\""+FileExist+colourType+"/"+oriFName+"\",\"numbers\":\""+rowCountCol+"_"+rowCountBlack+"\"}";*/
		out.write(result);
	}
}
